﻿using System;
using System.Data.SQLite;
using System.Web.UI;
using WebForm.Helper;

namespace WebForm
{
	public partial class UserDetail : Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				string userId = Request.QueryString["ID"];
				string sql = "SELECT ID, Name, Gender,Email,PhoneNumber, DateOfBirth FROM Users WHERE ID = @UserID";
				var parameters = new SQLiteParameter("@UserID", userId);
				var dataTable = DbHelper.ExecuteDataTable(sql,parameters);
				if (dataTable.Rows.Count > 0)
				{
					lblName.Text = dataTable.Rows[0]["Name"].ToString();
					lblEmail.Text = dataTable.Rows[0]["Email"].ToString();
					lblGender.Text = int.Parse(dataTable.Rows[0]["Gender"].ToString()) == 1 ? "Male" : "Female";
					lblPhoneNumber.Text = dataTable.Rows[0]["PhoneNumber"].ToString();
					lblDateOfBirth.Text = DateTime.Parse(dataTable.Rows[0]["DateOfBirth"].ToString()).ToShortDateString();
				}
				else
				{
					Response.Write("<script>alert('User Not Found')</script>");
				}
			}
		}
	}
}
